﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using ThuPhap.Controls;
using ThuPhap.ViewModels;

namespace ThuPhap.Models
{
    public class FontFamilyManage : BaseViewModel
    {
        private string fontName;

        public string FontName
        {
            get { return fontName; }
            set
            {
                if (value != fontName)
                {
                    fontName = value;
                    NotifyPropertyChanged("FontName");
                }
            }
        }

        private FontFamily fontFamily;

        public FontFamily FontFamily
        {
            get { return fontFamily; }
            set
            {
                if (value != fontFamily)
                {
                    fontFamily = value;
                    NotifyPropertyChanged("FontFamily");
                }
            }
        }

        public List<FontFamilyManage> Load()
        {
            //var allFonts = App.Current.Resources.Keys;

            var allFonts = App.Current.Resources.Keys;
            List<string> allFontKeys = new List<string>();
            foreach (var item in allFonts)
            {
                var name = item as string;
                if (name.Contains("Font_") == true)
                {
                    allFontKeys.Add(name);
                }
            }
            List<FontFamilyManage> listResults = new List<FontFamilyManage>();
            var resources = Application.Current.Resources;
            foreach (var item in allFontKeys)
            {
                FontFamily fontFamily = resources[item] as System.Windows.Media.FontFamily;
                string source = fontFamily.Source;
                FontFamilyManage font = new FontFamilyManage()
                {
                    FontName = source.Substring(source.IndexOf("#")+1),
                    FontFamily = fontFamily
                };

                listResults.Add(font);
            }
            return listResults;
        }
    }
}
